# Maintainer: @naveen521kk on Github Naveen M K <naveen521kk@gmail.com>

_realname=poetry-core
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=1.4.0
pkgrel=2
pkgdesc="Poetry PEP 517 Build Backend (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://github.com/python-poetry/poetry-core"
license=('spdx:MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-build")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest-mock"
              "${MINGW_PACKAGE_PREFIX}-python-pytest")
depends=("${MINGW_PACKAGE_PREFIX}-python")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname/-/_}-${pkgver}.tar.gz"
        "0002-msys-git-support.patch")
sha256sums=('514bd33c30e0bf56b0ed44ee15e120d7e47b61ad908b2b1011da68c48a84ada9'
            'aa476415abd8e586f6a92dbcc3be15410e3299d4bb2c3c9c65c4f9b7ebd0a5e4')

prepare() {
  cd "${srcdir}/${_realname/-/_}-${pkgver}"

  patch -p1 -i ${srcdir}/0002-msys-git-support.patch
}


build() {
  cd "${srcdir}"
  cp -r "${_realname/-/_}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python -m pytest || echo "test failed"
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}"/share/licenses/python-${_realname}/LICENSE
}
